const myPromise = function (fun) {
    var res = null;
    var callback = null;
    function resolve(val) {
        if (typeof callback === 'function') {
            res = callback(val);
        }
    }
    function reject(val) {
        if (typeof callback === 'function') {
            res = callback(val);
        }
    }
    this.then = function (fu) {
        callback = fu;
        return new myPromise(function (resolve, reject) {
            setTimeout(() => {
                resolve(res)
            }, 2000);
        })
    }
    this.finally = function (fu) {
        setTimeout(() => {
            fu()
        }, 2000);
    }

    fun(resolve, reject)
}

new myPromise((r, j) => {
    setTimeout(() => {
        r('1111')
    }, 2000);
}).then((res) => {
    console.log(res);
    return 222;
}).then(res => {
    console.log(res);
}).finally(() => {
    console.log('hahahah');
})